package com.cutie.entry.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.cutie.core.dao.DBManager;
import com.cutie.core.dao.IBuilder;
import com.cutie.entry.model.EntryDictionary;

public class EntryDictionaryDao {

	private static final String find_entry_sql = "select entry_dictionary_id,user_id,course_name,entry_name,entry_name_cn,image_source,entry_state from entry_dictionary where entry_name = ?";
	@SuppressWarnings("unchecked")
	public List<EntryDictionary> getEntries(String entryName) throws SQLException{
		try{
			Object[] data = new Object[]{ entryName };
			List<EntryDictionary> entryList = (List<EntryDictionary>)DBManager.executeQuery(find_entry_sql, data, new IBuilder(){

				@Override
				public Object build(ResultSet rs) throws SQLException {
					List<EntryDictionary> list = new ArrayList<EntryDictionary>();
					while(rs.next()){
						EntryDictionary entry = new EntryDictionary();
						entry.setEntryDictrionaryId(rs.getInt("entry_dictionary_id"));
						entry.setUserId(rs.getInt("user_id"));
						entry.setCourseName(rs.getString("course_name"));
						entry.setEntryName(rs.getString("entry_name"));
						entry.setEntryNameCN(rs.getString("entry_name_cn"));
						entry.setImageSource(rs.getString("image_source"));
						entry.setEntryState(rs.getInt("entry_state"));
						
						list.add(entry);
					}
					return list;
				}
				
			});
			return entryList;
		}catch(SQLException e){
			e.printStackTrace();
			throw e;
		}
	}
	
	
}
